package com.gec.hawsteproject.hawaste.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gec.hawsteproject.hawaste.domain.QualificationDo;
import com.gec.hawsteproject.hawaste.entity.Qualification;
import com.gec.hawsteproject.hawaste.mapper.QualificationMapper;
import com.gec.hawsteproject.hawaste.service.IQualificationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author gec
 * @since 2021-03-08
 */
@Service
public class QualificationServiceImpl extends ServiceImpl<QualificationMapper, Qualification> implements IQualificationService {


    /**
     * 根据动态条件分页查询qualification
     * @param page      分页对象
     * @param params    查询动态条件
     * @return
     */
    @Override
    public IPage<QualificationDo> selectByCondition(IPage<QualificationDo> page, Map<String, Object> params){
        QueryWrapper<QualificationDo> query = new QueryWrapper<>();
        //拼接动态sql，第一个参数为false则不生成该拼接语句
        query.eq("qu.del_flag","0")
                .eq(params.containsKey("type")&&!ObjectUtils.isEmpty(params.get("type")),"qu.type",params.get("type"))
                .eq(params.containsKey("check")&&!ObjectUtils.isEmpty(params.get("check")),"qu.`check`",params.get("check"))
                .ge(params.containsKey("startDate")&&!ObjectUtils.isEmpty(params.get("startDate")),"DATE(qu.create_date)",params.get("startDate"))
                .le(params.containsKey("endDate")&&!ObjectUtils.isEmpty(params.get("endDate")),"DATE(qu.create_date)",params.get("endDate"));
        System.out.println(query.getTargetSql());//获取当前的拼接sql
        return baseMapper.selectByCondition(page,query);
    }
}

